package com.hd.service.impl;

import com.hd.dao.BaseDao;
import com.hd.entity.Msg;
import com.hd.service.MsgService;
import com.hd.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service("msgService")
public class MsgServiceImpl implements MsgService {
    @Autowired
    private BaseDao<Msg,String>msgDao;
    @Override
    public void save(Msg msg){
        msg.setCreateTime(new Date());
        msgDao.save(msg);
    }

    @Override
    public void update(String id,Integer status) {
        String hql="update Msg set status=? where id=?";
        msgDao.execute(hql,status,id);
    }

    @Override
    public Msg get(String id) {
        return msgDao.get(Msg.class,id);
    }

    @Override
    public void updateByIdsAndStatus(String ids, Integer status) {
        String hql="update Msg set status=? where id in(?)";
        msgDao.execute(hql,status, StringUtils.convertSingleStr(ids));
    }

    @Override
    public void update(String objId, Integer status, String type) {
        String hql="update Msg set status=? where objId=? and type=?";
        msgDao.execute(hql,status,objId,type);
    }

    @Override
    public void deleteByParams(String objId, String type) {
        String hql="delete from Msg where objId=? and type=?";
        msgDao.execute(hql,objId,type);
    }

    @Override
    public void deleteByParams(String objId, String type,String receiver) {
        String hql="delete from Msg where objId=? and type=? and receiver=?";
        msgDao.execute(hql,objId,type,receiver);
    }
}
